package Sort;

import java.util.Arrays;

public class ShellSort {
    public void operation(int[] arr) {
        int gap = arr.length;
        while (gap > 1) {
            gap /= 2;
            for (int i = 1; i < arr.length; i+=gap) {
                int tmp = arr[i];
                int j = i - gap;
                for (; j >= 0; j-=gap) {
                    if (arr[j] > tmp) {
                        arr[j + gap] = arr[j];
                    } else {
                        break;
                    }
                }
                arr[j + gap] = tmp;
            }
        }
    }

    public static void main(String[] args) {
        ShellSort shellSort = new ShellSort();
        int[] arr = new int[]{9,8,7,6,5,4,3,2,1};
        shellSort.operation(arr);

        System.out.println(Arrays.toString(arr));
    }
}
